package com.aurora.blog.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aurora.common.log.annotation.Log;
import com.aurora.common.log.enums.BusinessType;
import com.aurora.common.security.annotation.RequiresPermissions;
import com.aurora.blog.domain.BlogPoem;
import com.aurora.blog.service.IBlogPoemService;
import com.aurora.common.core.web.controller.BaseController;
import com.aurora.common.core.web.domain.AjaxResult;
import com.aurora.common.core.utils.poi.ExcelUtil;
import com.aurora.common.core.web.page.TableDataInfo;

/**
 * 诗句Controller
 * 
 * @author aurora
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/blogPoem")
public class BlogPoemController extends BaseController
{
    @Autowired
    private IBlogPoemService blogPoemService;

    /**
     * 查询诗句列表
     */
    @RequiresPermissions("blog:blogPoem:list")
    @GetMapping("/list")
    public TableDataInfo list(BlogPoem blogPoem)
    {
        startPage();
        List<BlogPoem> list = blogPoemService.selectBlogPoemList(blogPoem);
        return getDataTable(list);
    }

    @GetMapping("/getPoemList")
    public TableDataInfo getPoemList(BlogPoem blogPoem)
    {
        startPage();
        List<BlogPoem> list = blogPoemService.selectBlogPoemList(blogPoem);
        return getDataTable(list);
    }

    /**
     * 导出诗句列表
     */
    @RequiresPermissions("blog:blogPoem:export")
    @Log(title = "诗句", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlogPoem blogPoem)
    {
        List<BlogPoem> list = blogPoemService.selectBlogPoemList(blogPoem);
        ExcelUtil<BlogPoem> util = new ExcelUtil<BlogPoem>(BlogPoem.class);
        util.exportExcel(response, list, "诗句数据");
    }

    /**
     * 获取诗句详细信息
     */
    @RequiresPermissions("blog:blogPoem:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(blogPoemService.selectBlogPoemById(id));
    }

    /**
     * 新增诗句
     */
    @RequiresPermissions("blog:blogPoem:add")
    @Log(title = "诗句", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogPoem blogPoem)
    {
        return toAjax(blogPoemService.insertBlogPoem(blogPoem));
    }

    /**
     * 修改诗句
     */
    @RequiresPermissions("blog:blogPoem:edit")
    @Log(title = "诗句", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogPoem blogPoem)
    {
        return toAjax(blogPoemService.updateBlogPoem(blogPoem));
    }

    /**
     * 删除诗句
     */
    @RequiresPermissions("blog:blogPoem:remove")
    @Log(title = "诗句", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(blogPoemService.deleteBlogPoemByIds(ids));
    }
}
